<template>
	<view class="container"><yxylInputs :inputs="inputs" @confirm="confirm"></yxylInputs></view>
</template>

<script>
import yxylInputs from '@/components/yxyl-inputs/yxyl-inputs.vue';
export default {
	components: { yxylInputs },
	data() {
		return {
			inputs: [],
			deviceId: ''
		};
	},
	onLoad(e) {
		// #ifdef H5
		this.$wechat.hideMenu();
		// #endif
		this.deviceId = e.deviceId;
		this.inputs.push({ title: '社区名称', key: 'communityName', placeholder: '请输入社区名称', required: true, type: 'text', errMsg: '请输入社区名称' });
		this.inputs.push({ title: '省市区', keys: ['provinceId', 'cityId', 'areaId'], type: 'address', level: 3 });
		this.inputs.push({ title: '详细地址', key: 'address', placeholder: '请输入详细地址', type: 'text', errMsg: '请输入详细地址' });
		this.inputs.push({ title: '管理员', key: 'communityAdminName', placeholder: '请输入管理员', required: true, type: 'text', errMsg: '请输入管理员' });
		this.inputs.push({ title: '联系人', key: 'contacts', placeholder: '请输入联系人', required: true, type: 'text', errMsg: '请输入联系人' });
		this.inputs.push({ title: '电话号码', key: 'telephone', placeholder: '请输入电话号码', required: true, type: 'number', errMsg: '请输入电话号码' });
	},
	methods: {
		confirm(e) {
			e.deviceId = this.deviceId;
			this.$http
				.request({
					url: 'api/Community/CreateByClient',
					method: 'PUT',
					data: e
				})
				.then(() => {
					uni.showToast({
						title: '创建成功',
						success() {
							setTimeout(function() {
								uni.redirectTo({
									url: 'list'
								});
							}, 1500);
						}
					});
				});
		}
	}
};
</script>

<style lang="scss" scoped></style>
